#include "BottomBar.h"

BottomBar::BottomBar(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);

	initAllSignal();
}

BottomBar::~BottomBar()
{}

void BottomBar::setPlayIcon()
{
	ui.btn_play->setIcon(QIcon("icons/player-play.png"));
}

void BottomBar::setPauseIcon()
{
	ui.btn_play->setIcon(QIcon(":/icons/player-pause-01.png"));
}

bool BottomBar::isSliderDown() const
{
	return ui.slider_play->isSliderDown();
}

void BottomBar::setSliderValue(int val)
{
	ui.slider_play->setValue(val);
}

void BottomBar::initAllSignal()
{
	initBtnSignal();
	initSliderSignal();
}

void BottomBar::initBtnSignal()
{
	connect(ui.btn_prev, &QPushButton::clicked, [this](bool clicked) {
		emit btnPrevMusic(clicked);
		});

	connect(ui.btn_play, &QPushButton::clicked, [this](bool clicked) {
		emit btnPlayMusic(clicked);
		});
	connect(ui.btn_next, &QPushButton::clicked, [this](bool clicked) {
		emit btnNextMusic(clicked);
		});
}

void BottomBar::initSliderSignal()
{
	connect(ui.slider_play, &QSlider::sliderReleased, this, 
		[this]() {
			emit sliderReleasedValue(ui.slider_play->value());
		});
}

void BottomBar::setSliderRange(int min_ms, int max_ms)
{
	ui.slider_play->setRange(min_ms, max_ms);
}